太久沒寫程式 被語法跟括號少括折磨好久
題目敘述:
66. Plus One
You are given a large integer represented as an integer array digits, where each digits[i] is the ith digit of the integer. The digits are ordered from most significant to least significant in left-to-right order. The large integer does not contain any leading 0's.
Increment the large integer by one and return the resulting array of digits.
class Solution {
public:
vector<int> plusOne(vector<int>& digits) {
int size=digits.size();
digits[size-1]+=1;
for(int i=size-1;i>=0;i--){
if(digits[i]>=10){
digits[i]%=10;
if(i>0){
digits[i-1]+=1;
}
else{
digits.insert(digits.begin(), 1);
}
}
else {
break;
}
}
return digits;
}
};